package com.example.forum.utils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: DongGuoZhen
 * @Date: 2024/03/13/17:00
 * @Description:
 */
public class Util {
    public static void main1(String[] args) {
        int[][] arr = {{8, 0}, {1, 2}, {3, 4}, {6, 6}, {8, 1}, {11, 3}, {6, 5}};
        int[][] SortData = selectionSort(arr);
        for (int[] item : SortData) {
            System.out.println("[" + item[0] + ", " + item[1] + "]");
        }
    }
    public static int[][] selectionSort(int[][] arr) {
        int n = arr.length;
        for (int i = 0; i < n - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < n; j++) {
                if (arr[j][0] < arr[minIndex][0] || (arr[j][0] == arr[minIndex][0] && arr[j][1] < arr[minIndex][1])) {
                    minIndex = j;
                }
            }
            int[] temp = arr[minIndex];
            arr[minIndex] = arr[i];
            arr[i] = temp;
        }
        return arr;
    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        System.out.println(One(str)); //第一种方法
        System.out.println(Two(str));  //第二种方法
    }

    public static void main3(String[] args) {
        int[] arr = new int[]{1,4,2,3,6,9,0};
        System.out.println(Arrays.toString(sort1(arr)));
    }

    public static String One(String s) {
        Set<Character> set = new HashSet<>();
        int left = 0;
        int right = 0;
        int maxLength = 0;
        String str = "";
        while (right < s.length()) {
            if (!set.contains(s.charAt(right))) {
                set.add(s.charAt(right));
                if (right - left + 1 > maxLength) {
                    maxLength = right - left + 1;
                    str = s.substring(left, right + 1);
                }
                right++;
            } else {
                set.remove(s.charAt(left));
                left++;
            }
        }
        return str;
    }

    public static Set<Character> Two(String s) {
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            set.add(ch);
        }
        return set;
    }

    public static int[] sort(int[] arr) {
        int temp = 0;
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j] > arr[j+1]) {
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        return arr;
    }
    
    
    public static int[] sort1(int[] arr) {
        int temp = 0;
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            for (int j = i+1; j < arr.length; j++) {
                if(arr[min] > arr[j]) {
                    min = j;
                }
            }
            temp = arr[min];
            arr[min] = arr[i];
            arr[i] = temp;
        }
        return arr;
    }
}
